package com.youkeda.kafka.study.listener;

import com.alibaba.fastjson.JSON;
import com.youkeda.kafka.study.model.Student;
import com.youkeda.kafka.study.service.StudyDataService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName KafkaStreamListener
 * @Author 刘正星
 * @Date 2021/4/29 上午11:37
 * @Description
 */
@Component
public class KafkaStreamListener {
    private static final Logger LOG = LoggerFactory.getLogger(KafkaStreamListener.class);

    @Autowired
    private StudyDataService studyDataService;

    /**
     * 统计 学习天数
     *
     * @param record
     */
    @KafkaListener(topics = "studyDateCount")
    public void studyDateCount(ConsumerRecord<String, String> record) {
        LOG.error("---- " + record.key());

        System.out.println(record.value());

        Student student = JSON.parseObject(record.value(),Student.class);

    }

    /**
     * 学习总时长
     *
     * @param record
     */
    @KafkaListener(topics = "studyDuration")
    public void studyDuration(ConsumerRecord<String, String> record) {
//        LOG.error("==== " + record.key());

    }

    /**
     * 学习节数
     *
     * @param record
     */
    @KafkaListener(topics = "studySections")
    public void studySections(ConsumerRecord<String, String> record) {
//        LOG.error(">>>> " + record.key());

    }

    /**
     * 代码行数
     *
     * @param record
     */
    @KafkaListener(topics = "studyCodeRows")
    public void studyCodeRows(ConsumerRecord<String, String> record) {
//        LOG.error(".... " + record.key());

    }
}
